<?php

namespace App\Models\User;

use App\Models\Common\CommonModel;
use App\Models\Rbac\GuardUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class LiPeiSum extends CommonModel
{
    use HasFactory;
    protected $table = 'li_pei_order_sum';

    public function getGuardUser() {
        return $this->hasOne(GuardUser::class,'id','account')->withDefault(['name'=>'未知']);
    }


    public function getRecords(array $conditions) {
        $records =$this->newQuery(); // TODO: Change the autogenerated stub

        if(!empty($conditions['importNumber'])){
            $records = $records->where('import_number',$conditions['importNumber']);
        }
        if(!empty($conditions['createdAt'])){
            if(is_array($conditions['createdAt'])){
                $records->whereBetween('created_at',$conditions['createdAt']);
            }
            else{
                $records = $records->where('created_at',$conditions['createdAt']);
            }
        }
        return $records->orderByDesc('id');
    }
}
